﻿import com.gamepackage.tilemap.Layer;

class com.gamepackage.tilemap.layer.Multilayer implements com.gamepackage.tilemap.Layer
{
	private var height: Number;
	private var width: Number;

	private var layers: Array;
	private var ratios: Array;
	
	function Multilayer( width: Number, height: Number )
	{
		this.width = width;
		this.height = height;
		
		layers = new Array;
		ratios = new Array;
	}
	
	function addLayer( layer: Layer ): Void
	{
		layers.push( layer );
	}
	
	function setReferenceLayer( refLayer: Layer ): Void
	{
		var l: Number;
		var layer: Layer;
		
		for( l in layers )
		{
			layer = layers[l];
			
			if ( layer === refLayer )
			{
				ratios[l] = { x: 1, y: 1 };
			}
			else
			{
				ratios[l] = { x: 1 / ( refLayer.getLayerWidth() - width ) * ( layer.getLayerWidth() - width ), y: 1 / ( refLayer.getLayerHeight() - height ) * ( layer.getLayerHeight() - height ) };
			}
		}
	}
	
	function moveTo( x: Number, y: Number ): Void
	{
		var l: Number;
		var layer: Layer;
		var ratio: Object;
		
		for( l in layers )
		{
			layer = layers[l];
			
			ratio = ratios[l];
			
			layer.moveTo( x * ratio.x , y * ratio.y );
		}
	}

	//-- FILL UNUSED IMPLEMENTION --//
	function create( Void ): Void {};
	function getLayerWidth( Void ): Number{ return null };
	function getLayerHeight( Void ): Number{ return null };
	function getX( Void ): Number	{ return null; };
	function getY( Void ): Number { return null; };
	function getChildMovieClip( Void ): MovieClip { return null };
	function getDepthSpace( Void ): Number { return null };
}